#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "c-utils/utils.h"

int test_base64(int argc, char *argv[])
{
    unsigned char *raw_ctx = argv[1];
    unsigned char *enc_ctx = argv[2];
    if (3 != argc)
    {
        raw_ctx = "abcd1234";
        enc_ctx = "YWJjZDEyMzQ=";
    }
    size_t out_cap = (strlen(raw_ctx) + 1) / 3 * 4;
    unsigned char *out = calloc(out_cap, sizeof(char));

    int ret = 0;
    int len = utils_b64_encode(raw_ctx, strlen(raw_ctx), out);
    printf("input: %s, out len : %d, out data: %s\n", raw_ctx, len, out);
    if (strncmp(enc_ctx, out, len) != 0)
    {
        ret = -1;
        goto RETURN;
    }

    bzero(out, out_cap);
    len = utils_b64_decode(enc_ctx, strlen(enc_ctx), out);
    printf("out len: %d, out data: %s\n", len, out);
    if (strncmp(out, raw_ctx, len) != 0)
        ret = -1;
RETURN:
    free(out);
    return ret;
}